package com.bawei.home.repo

import androidx.lifecycle.MutableLiveData
import io.reactivex.Observer
import com.bw.lib_mvvm.entity.BaseVideoEntity
import com.bw.lib_mvvm.entity.SimpleVideo
import com.bw.lib_mvvm.BaseRepo
import com.bw.lib_mvvm.entity.HomeType
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers

class SimpleVideoRepo: BaseRepo() {


    fun getVideo(
        page:Int,
        pagesize :Int,
        success:MutableLiveData<BaseVideoEntity<SimpleVideo>>,
        failed:MutableLiveData<String>
    ){
        getService().getVideoData(page, pagesize)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .safeSubscribe(object :Observer<BaseVideoEntity<SimpleVideo>>{
                override fun onSubscribe(d: Disposable) {

                }

                override fun onError(e: Throwable) {
                    failed.value=e.message
                }

                override fun onComplete() {

                }

                override fun onNext(t: BaseVideoEntity<SimpleVideo>) {
                    success.value=t
                }

            })
    }

    fun getType(
        typesuccess: MutableLiveData<HomeType>,
        typefailed:MutableLiveData<String>,
    ){
        getService().getTypeVideo()
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object :Observer<HomeType>{
                override fun onSubscribe(d: Disposable) {

                }

                override fun onError(e: Throwable) {
                    typefailed.value=e.message
                }

                override fun onComplete() {

                }

                override fun onNext(t: HomeType) {
                    typesuccess.value=t
                }

            })
    }


}